<template>
  <div class="table">
    <list-table-new
      v-bind="tableConfig"
      v-show="showTable"
      ref="listTable"
    ></list-table-new>
    <edit-page
      v-if="!showTable"
      @goBackPage="goBackPage"
      :rightBtnArr="rightBtnArr"
    >
      <detail-page :detailData="detailData" />
    </edit-page>
  </div>
</template>

<script>
import detailPage from "./detailPage.vue";
import { getOrgList } from "@/api/systemManagement/orgnizationManagement.js";
export default {
  components: {
    detailPage,
  },
  props: ["queryId"],
  data() {
    return {
      detailData: [],
      showTable: true,
      rightBtnArr: [
        {
          icon: "",
          text: "保存",
          hide: false,
          methods: () => {},
        },
      ],
      tableConfig: {
        showAllSearch: false,
        showIndex: true,
        selectionShow: false,
        showFilterBtn: false,
        showCustomBtn: false,
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          searchArr: [],
          queryData: {
            page: 1,
            pageSize: 15,
          },
        },
        tableMethods: {
          rowClick: (e) => {},
        },
        column: [
          {
            label: "组织名称",
            textAlign: "left",
            prop: "name",
          },
          {
            label: "所属应用",
            textAlign: "left",
            prop: "appName",
          },
          {
            label: "组织级别",
            textAlign: "left",
            prop: "level",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "system_org_level",
                row.level
              );
            },
          },
          {
            label: "是否外单位",
            textAlign: "left",
            prop: "outOrg",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "system_orgout",
                row.outOrg
              );
            },
          },
        ],
        tableData: [],
        paginationObj: {
          pageSizes: [15, 30, 50, 100],
        },
        totalNumber: 0,
      },
    };
  },
  created() {},
  watch: {
    queryId: {
      handler(val) {
        this.$refs.listTable.searchData();
      },
    },
  },
  methods: {
    init() {
      this.$refs.listTable.searchData();
    },
    //获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryData.parent = this.queryId.id;
      getOrgList(queryData).then((res) => {
        this.$set(this.tableConfig, "tableData", res.data);
        this.$set(this.tableConfig, "totalNumber", res.total);
      });
    },
    goBackPage(value) {
      this.showTable = value;
    },
  },
};
</script>

<style lang="less" scoped>
.table {
  width: 100%;
  height: 100%;
}
</style>
